import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpEchoClient {
    private Socket socket = null;
    private String serverIp;
    private int serverPort;

    public TcpEchoClient(String ip, int port) throws IOException {
        socket = new Socket(ip, port);
    }

    public void start(){
        try(InputStream inputStream = socket.getInputStream();
            OutputStream outputStream = socket.getOutputStream()) {
            while(true){
                PrintWriter writer = new PrintWriter(outputStream);
                Scanner sc = new Scanner(System.in);
                String request = sc.next();
                writer.println(request);
                writer.flush();
                Scanner getSc = new Scanner(inputStream);
                String response = getSc.next();
                System.out.println(response);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException {
        TcpEchoClient client = new TcpEchoClient("127.0.0.1", 8080);
        client.start();
    }
}
